# TODO
from cs50 import get_int

def main():
    digit1 = 0
    digit2 = 0
    digit = 0
    size = 0
    checksum = 0
    cc_number = get_int("Number: ")
    remain_digits = cc_number


    while remain_digits > 0:
        digit = remain_digits % 10
        remain_digits //= 10

        if size > 0:
            digit2 = digit1

        digit1 = digit

        if size % 2 == 0:
            checksum += digit
        else:
            checksum += (digit * 2) % 10 + (digit * 2) // 10

        size += 1


    if checksum % 10 != 0:
        print("INVALID")
        return

    # 判断是哪一家的银行卡
    # AMEX
    if size == 15 and digit1 == 3 and (digit2 == 4 or digit2 == 7):
        print("AMEX")
        return

    # MASTERCARD
    if size == 16 and digit1 == 5 and (digit2 >= 1 and digit2 <= 5):
        print("MASTERCARD")
        return

    # VISA
    if (size == 13 or size == 16) and digit1 == 4:
        print("VISA")
        return

    # 如果不符合上述条件，输出无效
    print("INVALID")


if __name__ == "__main__":
    main()


